package com.mq.config5_comfirm;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ConfirmConfig {

    /**
     * - 交换机：`confirm.direct.exchange`
     * - 队列：`confirm.queue`
     * - 路由key： `msg.confirm`
     */
    @Bean
    public DirectExchange confirmExchange() {
        return new DirectExchange("confirm.direct.exchange");
    }

    //创建队列
    @Bean
    public Queue confirmQueue() {
        return new Queue("confirm.queue");
    }

    //队列绑定到交换机
    @Bean
    public Binding confirmToDirectExchange(
            @Qualifier("confirmQueue") Queue confirmQueue,
            @Qualifier("confirmExchange") DirectExchange confirmExchange) {
        return BindingBuilder.bind(confirmQueue).to(confirmExchange).with("msg.confirm");
    }
}